package tests;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 */
public class ShoppingCartPage extends Utils {
    public static String url = "http://49.235.61.184/?s=cart/index.html";
    public static String settlementUrl = null;
    public ShoppingCartPage() {
        super(url);
    }
    /**
     * 检查页面
     */
    public void checkShoppingCartPage() throws IOException {
        //检查表头
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.am-container.cart-table.am-background-white.am-radius.am-margin-bottom-main > table > thead > tr"));
        //检查购物车页面商品
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.am-container.cart-table.am-background-white.am-radius.am-margin-bottom-main > table > tbody"));
        //检查“全选”按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.cart-nav.am-box-shadow-top.am-background-white > div > div.nav-left.am-fl.am-padding-left > label > span.el-text.am-color-grey-dark"));
        //检查“删除”按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.cart-nav.am-box-shadow-top.am-background-white > div > div.nav-left.am-fl.am-padding-left > a.am-margin-left-main.nav-delete-submit.am-color-grey-dark.submit-ajax"));
        //检查“收藏”按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.cart-nav.am-box-shadow-top.am-background-white > div > div.nav-left.am-fl.am-padding-left > a.am-margin-left-main.nav-collect-submit.am-color-grey-dark.submit-ajax"));
        //检查“结算”按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.cart-nav.am-box-shadow-top.am-background-white > div > div.nav-right.am-fr.am-padding-right > form > button"));
        //检查已选商品?件
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.cart-nav.am-box-shadow-top.am-background-white > div > div.nav-right.am-fr.am-padding-right > form > span.selected-tips.am-color-grey-dark"));
        //检查合计：
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.cart-nav.am-box-shadow-top.am-background-white > div > div.nav-right.am-fr.am-padding-right > form > span.total-price-tips.am-color-grey-dark"));
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
    }
    /**
     * 测试一：收藏商品
     */
    public void scCollectedItems() throws IOException, InterruptedException {
        //收藏单个商品
        driver.findElement(By.cssSelector("div > a.am-color-grey-dark.submit-ajax")).click();
        Thread.sleep(1000);
        String str = driver.findElement(By.cssSelector("div > a.am-color-grey-dark.submit-ajax")).getText();
        assert str.equals("已收藏");
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());

        //收藏多个商品
        //点击“全选”按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.cart-nav.am-box-shadow-top.am-background-white > div > div.nav-left.am-fl.am-padding-left > label > span.am-ucheck-icons")).click();
        //点击“收藏”按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.cart-nav.am-box-shadow-top.am-background-white > div > div.nav-left.am-fl.am-padding-left > a.am-margin-left-main.nav-collect-submit.am-color-grey-dark.submit-ajax")).click();
        //屏幕截图
        Thread.sleep(2000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
    }

    /**
     * 测试二：删除商品
     */
     public void scDeleteProduct() throws InterruptedException, IOException {
         //删除单个商品
         driver.findElement(By.cssSelector("td.operation > div > a.am-color-grey-dark.submit-delete")).click();
         //弹出提示框，点击“确认”按钮
         driver.findElement(By.cssSelector("span.am-modal-btn[data-am-modal-confirm]")).click();
         //屏幕截图
         Thread.sleep(1000);
         ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());

         //勾选商品进行删除
         driver.findElement(By.cssSelector("span > i.am-icon-checked")).click();
         driver.findElement(By.cssSelector("td.operation > div > a.am-color-grey-dark.submit-delete")).click();
         //弹出提示框，点击“确认”按钮
         driver.findElement(By.cssSelector("span.am-modal-btn[data-am-modal-confirm]")).click();
         //屏幕截图
         Thread.sleep(1000);
         ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());

         //全部删除
         //点击“全选”按钮
         driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.cart-nav.am-box-shadow-top.am-background-white > div > div.nav-left.am-fl.am-padding-left > label > span.am-ucheck-icons")).click();
         //点击“删除”按钮
         driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.cart-nav.am-box-shadow-top.am-background-white > div > div.nav-left.am-fl.am-padding-left > a.am-margin-left-main.nav-delete-submit.am-color-grey-dark.submit-ajax")).click();
         //弹出提示框，点击“确认”按钮
         driver.findElement(By.cssSelector("span.am-modal-btn[data-am-modal-confirm]")).click();
         //屏幕截图
         Thread.sleep(2000);
         ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());


     }

    /**
     * 测试三：结算商品
     */
    public void scCheckoutItems() throws InterruptedException, IOException {
        //修改数量
        driver.findElement(By.cssSelector("td.number > div > span:nth-child(3)")).click();
        Thread.sleep(1000);
        //勾选商品
        driver.findElement(By.cssSelector("span > i.am-icon-checked")).click();
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //点击“结算”按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.cart-nav.am-box-shadow-top.am-background-white > div > div.nav-right.am-fr.am-padding-right > form > button")).click();
        //屏幕截图
        Thread.sleep(1000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //后退
        driver.navigate().back();

        //点击“全选”按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.cart-nav.am-box-shadow-top.am-background-white > div > div.nav-left.am-fl.am-padding-left > label > span.am-ucheck-icons")).click();
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //点击“结算”按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.cart-nav.am-box-shadow-top.am-background-white > div > div.nav-right.am-fr.am-padding-right > form > button")).click();
        Thread.sleep(2000);
        settlementUrl = driver.getCurrentUrl();
        //屏幕截图
        Thread.sleep(1000);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //后退
        driver.navigate().back();

        Thread.sleep(2000);
        //点击“全选”按钮
        driver.findElement(By.cssSelector("body > div.body-content-container > div.body-content-formal-container > div.cart-content > div.cart-nav.am-box-shadow-top.am-background-white > div > div.nav-left.am-fl.am-padding-left > label > span.am-ucheck-icons")).click();
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
    }

}
